//
//  BindingBankCardTableViewController.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/6/17.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "BindingBankCardTableViewController.h"
#import "LogInPassWordFooterView.h"
#import "BindingBankCardTableViewCell.h"

@interface BindingBankCardTableViewController ()<didClickBindingBankCardButtonDelegate,LogInPassWordFooterDelegate>

@property (nonatomic,strong)NSArray *leftArray;

@property (nonatomic,strong)NSArray *rightArray;

@property (nonatomic,strong)NSMutableArray *textFieldMutableArray;

@end

static NSString *const reuseIdentifier = @"reuseIdentifier";

@implementation BindingBankCardTableViewController

- (NSMutableArray *)textFieldMutableArray {
    if (!_textFieldMutableArray) {
        _textFieldMutableArray = [NSMutableArray array];
    }
    return _textFieldMutableArray;
}

-(NSArray *)leftArray {
    if (!_leftArray) {
        
        NSString *path = [[NSBundle mainBundle]pathForResource:@"BindingBankCardLeft" ofType:@"plist"];
        _leftArray = [NSArray arrayWithContentsOfFile:path];
        
    }
    return _leftArray;
}

- (NSArray *)rightArray {
    if (!_rightArray) {
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"BindingBankCardRight" ofType:@"plist"];
        _rightArray = [NSArray arrayWithContentsOfFile:path];
    }
    return _rightArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"绑定银行卡";
    
    self.tableView.backgroundColor = BACKGROUND_COLOR;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BindingBankCardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    
    if (!cell) {
        cell = [[BindingBankCardTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.leftLabel.text = self.leftArray[indexPath.row];
    cell.rightTextField.placeholder = self.rightArray[indexPath.row];
    
    if (indexPath.row == 3) {
        cell.rightButton.hidden = NO;
        cell.delegate = self;
    }
    
    if (indexPath.row != 2) {
        cell.rightTextField.keyboardType = UIKeyboardTypeNumberPad;
    }
    
    [self.textFieldMutableArray addObject:cell.rightTextField];
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return HEIGHT/5;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    LogInPassWordFooterView *footer = [[LogInPassWordFooterView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT/5)];
    footer.delegate = self;
    return footer;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    [self clearResignFirstResponder];
}

- (void)clearResignFirstResponder {
    for (UITextField *textField in self.textFieldMutableArray) {
        [textField resignFirstResponder];
    }
}

- (void)didClickBindingBnakCardButton:(UIButton *)button {
    NSLog(@"获取验证码按钮");
}

- (void)LogInPassWordFooterViewButton:(UIButton *)button {
    [self clearResignFirstResponder];
    NSLog(@"确认按钮");
}

@end
